package com.beta.platform.rest.auth;

import com.beta.platform.rest.constant.UserType;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 当前用户登录信息
 *
 * @author wikili
 */
@Data
@JsonIgnoreProperties(ignoreUnknown = true)
public class LoginAccountDetail {

    public LoginAccountDetail() {
    }

    /**
     * c端用户
     *
     * @param id
     * @param account
     */
    public LoginAccountDetail(String id, String account) {
        this.id = id;
        this.userType = UserType.MEMBER;
        this.account = account;
        this.loginTime = LocalDateTime.now();
    }

    public LoginAccountDetail(String id, String account, Long partnerId, List<String> roleCodes) {
        this.id = id;
        this.account = account;
        this.roleCodes = roleCodes;
        this.partnerId = partnerId;
        this.userType = UserType.USER;
        this.loginTime = LocalDateTime.now();
    }

    private String id;

    private Long partnerId;

    /**
     * c端用户没有roleCodes
     */
    private UserType userType;

    private String account;

    private ThirdUserInfo  thirdUserInfo;

    private String name;

    private List<String> roleCodes;

    private List<Long> roleIds;

    private List<DataAuth> dataAuths;

    @JsonIgnore
    private LocalDateTime loginTime;

    /**
     * 用户的id和uuid会作为key保存到redis
     */
    private String uuid;

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public static class DataAuth{

    	private DataAuthType type;

    	private List<DataItem> dataItemList;
    }

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public static class DataItem{

    	private Long id;

    	private String code;
    }
}
